package com.peter.design.pattern.template;

/**
 * @Auther: 肖冬
 * @Date: 2020/8/1 02:11
 * @Description:
 */
public abstract class AbstractPageBuilder implements PageBuilder{

    private static final String DEFAULT_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";

    private static final String DEFAULT_XMLNS = "http://www.w3.org/1999/xhtml";

    private StringBuffer stringBuffer = new StringBuffer();

    public String bulidHtml() {
        stringBuffer.append(DEFAULT_DOCTYPE);
        stringBuffer.append("<html xmlns=\"" + DEFAULT_XMLNS + "\">");
        stringBuffer.append("<head>");
        appendTitle(stringBuffer);
        appendMeta(stringBuffer);
        appendLink(stringBuffer);
        appendScript(stringBuffer);
        stringBuffer.append("</head>");
        appendBody(stringBuffer);
        stringBuffer.append("</html>");
        return stringBuffer.toString();
    }

    //选择性覆盖
    protected void appendMeta(StringBuffer stringBuffer){
    }
    //选择性覆盖
    protected void appendLink(StringBuffer stringBuffer){
    }
    //选择性覆盖
    protected void appendScript(StringBuffer stringBuffer){
    }

    //必须覆盖
    protected abstract void appendTitle(StringBuffer stringBuffer);

    //必须覆盖
    protected abstract void appendBody(StringBuffer stringBuffer);

}